package com.lankystar.logistucs.spring.dao.impl;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.lankystar.logistucs.spring.dao.IAddressDao;
import com.lankystar.logistucs.spring.entity.Address;

@Repository
public class AddressDaoImpl extends BaseDaoImpl implements IAddressDao {

	@Autowired
	private SessionFactory sf;
	
	public Session getSession(){
		System.out.println("开启session！！AddressDaoImpl");
		return sf.getCurrentSession();
	}
	@Override
	public Address selectAddressById(int addressId) {
		Address address = (Address) getSession().get(Address.class, addressId);
		return address;
	}
	@SuppressWarnings("unchecked")
	@Override
	public List<Address> selectAddresslistByuserId(int userId) {
		String hql = "select a from Address a join a.user u where u.userId = ?";
		List<Address> addresslist = getSession().createQuery(hql).setInteger(0, userId).list();
		return addresslist;
	}

}
